// 代码雨，整个模块，配合index.html
let canvas:HTMLCanvasElement | null = document.querySelector("canvas");
if (!canvas) {
    throw new Error("Canvas not found");
}
let ctx = canvas.getContext("2d");
if (!ctx) {
    throw new Error("Context not found");
}
canvas.width = screen.availWidth;
canvas.height = screen.availHeight;

const str: string[] = "HelloTypeScript01010101".split('');
const arr = Array(Math.ceil(canvas.width / 10)).fill(0);
console.log(arr);

const rain = () => {
    ctx.fillStyle = 'rgba(0,0,0,0.05)';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = 'rgb(0,255,0)';
    arr.forEach((item, i) => {
        ctx.fillText(str[Math.floor(Math.random() * str.length)] || 'a', i * 10, item + 10);
        arr[i] = item > canvas.height || item > Math.random() * 10000 ? 0 : item + 10;
    })
    
}
setInterval(rain, 40);

